package com.gitee.hongruisun.promotion;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略 + 简单工厂 + 注册式单例
 */
public class PromotionStrategyFactory {

    private PromotionStrategyFactory(){}

    private static Map<String,IPromotionStrategy> PROMOTION_STRATEGY_MAP =
            new HashMap();

    private static final IPromotionStrategy NO_PROMOTION = new EmptyStrategy();
    static {
        PROMOTION_STRATEGY_MAP.put("CACH",new CashbackStrategy());
        PROMOTION_STRATEGY_MAP.put("COUP",new CouponStrategy());
        PROMOTION_STRATEGY_MAP.put("GROUP",new GroupbuyStrategy());
    }

    public static IPromotionStrategy getPromotionStrategy(String promotionKey){
        IPromotionStrategy promotionStrategy = PROMOTION_STRATEGY_MAP.get(promotionKey);
        return promotionStrategy == null ? NO_PROMOTION : promotionStrategy;
    }


}
